package com.guigu.service.impl.stock;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.guigu.mapper.stock.SCellMapper;
import com.guigu.pojo.manufacture.MDesignProcedure;
import com.guigu.pojo.stock.SCell;
import com.guigu.pojo.stock.SFirstProductArea;
import com.guigu.service.stock.SCellService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Mr.Zhang
 * @since 2024-12-06
 */
@Service
public class SCellServiceImpl extends ServiceImpl<SCellMapper, SCell> implements SCellService {

    @Autowired
    private SCellMapper sCellMapper;

    @Override
    public SCell getEndSCell() {
        QueryWrapper<SCell> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("STORE_ID");
        queryWrapper.last("limit 1");
        SCell sCell = sCellMapper.selectOne(queryWrapper);
        return sCell;
    }

    @Override
    public PageInfo<SCell> selectByPage(HashMap<String, Object> map) {
        Integer pageNum = 1;
        Integer pageSize = 5;

        Object pageNumObj = map.get("pageNum");
        if (pageNumObj != null && StringUtils.isNotBlank((String) pageNumObj)) {
            pageNum = Integer.parseInt((String) pageNumObj);
        }
        Object pageSizeObj = map.get("pageSize");
        if (pageSizeObj != null && StringUtils.isNotBlank((String) pageSizeObj)) {
            pageSize = Integer.parseInt((String) pageSizeObj);
        }
        QueryWrapper<SCell> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("CHECK_TAG","0","2");

        PageHelper.startPage(pageNum,pageSize);
        List<SCell> sCells = sCellMapper.selectList(queryWrapper);
        PageInfo<SCell> pageInfo = new PageInfo<>(sCells);
        return pageInfo;
    }
    @Override
    public SCell selectProductId(String productId) {
        QueryWrapper<SCell> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("PRODUCT_ID",productId);
        SCell sCell = sCellMapper.selectOne(queryWrapper);
        return sCell;
    }

    @Override
    public boolean updateProductId(SCell sCell) {
        //根据产品编号修改库存单元
        QueryWrapper<SCell> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("PRODUCT_ID",sCell.getProductId());
        int update = sCellMapper.update(sCell, queryWrapper);
        return update>0;
    }
}
